package com.mobilesales.android.infrastructure;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import android.content.Context;
import android.content.res.Configuration;

import com.mobilesales.android.R;

public class Language {

	private String name; 
	private String code;
	
	public Language(String name, String code) {
		this.name = name;
		this.code = code;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}
	
	public static Language getCurrentLanguage(Context ctx) {
		Locale lang = ctx.getResources().getConfiguration().locale;
		return new Language(lang.getDisplayName(),lang.getLanguage());
	}
	
	public static void setCurrentLanguage(Context ctx, String lang) {
		Locale locale = new Locale(lang);
		Locale.setDefault(locale);
		Configuration config = new Configuration();
		config.locale = locale;
		ctx.getResources().updateConfiguration(config, null);
	}
	
	public static List<Language> getAvailableLanguages(Context ctx) {
		List<Language> langs = new ArrayList<Language>();
		langs.add(new Language(ctx.getString(R.string.English), "en"));
		langs.add(new Language(ctx.getString(R.string.Polski), "pl"));
		return langs;
	}
	
	@Override
	public String toString() {
		return getName();
	}
}
